//
//  UserDefaultsManager.m
//  HHPLiveVideo
//
//  Created by 韩红坡 on 2017/2/22.
//  Copyright © 2017年 韩红坡. All rights reserved.
//

#import "UserDefaultsManager.h"

NSString *const kRecordCurrntTimeKey = @"RecordCurrntTimeKey";

@implementation UserDefaultsManager

+ (void)setBool:(BOOL)value forKey:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] setBool:value forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)setObject:(id)object forKey:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)boolForKey:(NSString *)key
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}

+ (id)objectForKey:(NSString *)key
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

+ (void)removeObjectForKey:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)saveCurrentTimestamp{
    NSDate * date = [NSDate dateWithTimeIntervalSinceNow:0];
    
    NSTimeInterval timeInterval = [date timeIntervalSince1970] * 1000;
    
    NSString * currentTime = [NSString stringWithFormat:@"%f",timeInterval];
    
    [[NSUserDefaults standardUserDefaults] setValue:currentTime forKey:kRecordCurrntTimeKey];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)showConformsIntervalTime:(NSInteger)intervalTime{
    
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
    
    NSTimeInterval interval = [date timeIntervalSince1970] * 1000;
    
    NSString *runBackTime = [[NSUserDefaults standardUserDefaults] objectForKey:kRecordCurrntTimeKey];
    
    long long int  time = (interval - runBackTime.longLongValue);
    
    if (time > intervalTime * 1000){
        
        return YES;
    }
    
    return NO;
}

@end
